<template>
  <div style="width:100%;height:100%">
    <v-chart :options="option" :initOptions="initOptions" :theme="theme" autoresize />
  </div>
</template>
<script>

export default {
  name: 'chart',
  props: ['index'],
  mounted () {
    console.log(this.getIndicator, this.getData)
  },
  data () {
    return {
      initOptions: { renderer: 'canvas' },
      theme: 'default'
    }
  },
  methods: {
  },
  computed: {
    insideSlideArray () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent
    },
    insideArrayIndex () {
      return this.insideSlideArray.indexOf(this.insideSlideArray.filter((currentValue) => {
        return currentValue.i === this.index
      })[0])
    },
    getDetail () {
      return this.$store.state.layout[this.$store.state.activeArrayIndex].SlideContent[this.insideArrayIndex].itemContent.detail
    },
    getIndicator () {
      var indicator = []
      for (let i = 1, nc = this.getDetail.nc; i < nc; i++) {
        indicator.push({
          name: this.getDetail.sheetData[0][i],
          max: this.getDetail.sheetData[1][i]
        })
      }
      return indicator
    },
    getData () {
      var data = []
      for (let i = 2, nr = this.getDetail.nr; i < nr; i++) {
        data.push({
          name: this.getDetail.sheetData[i][0],
          value: this.getDetail.sheetData[i].slice(1)
        })
      }
      return data
    },
    option () {
      return {
        animation: this.getDetail.animation,
        radar: {
          ...this.getDetail.simpleRadar,
          indicator: this.getIndicator
        },
        series: {
            type: 'radar',
            tooltip: {
                trigger: 'item'
            },
            areaStyle: this.getDetail.simpleRadar.areaStyle,
            data: this.getData
        },
        title: this.getDetail.title,
        legend: this.getDetail.legend,
        tooltip: {},
        color: this.getDetail.color[this.getDetail.color.option],
        backgroundColor: this.getDetail.backgroundColor[this.getDetail.backgroundColor.option]
      }
    }
  }
}
</script>
<style scoped>
  .echarts {
    width: 100%;
    height: 100%;
  }
</style>
<style>

</style>
